var entityCollection = require('../../../Base/server/controllers/EntityCollection');

//查找所有交接区ID
exports.distinctId = function(completeFun) {
    var connectArea = entityCollection.getEntity("WareHouse");
    connectArea.Entity.collection.distinct('_id', function(err, records) {
        if (err) {
            var newErr = new Error();
            newErr.leval = 9;
            newErr.title = '查询错误';
            newErr.message = '查询看板需求错误，请检查查询参数！';
            completeFun(newErr);
        } else {
            completeFun(null, records);
        }
    });
};

exports.getConnectAreaByDepartment = function(queryCondition, completeFun) {
    var entity = entityCollection.getEntity("WareHouse");
    entity.findOne(queryCondition, null, function(err, result) {
        if (err) {
            completeFun(err);
        } else {
            completeFun(null, result);
        }
    });
};

//通过作业获取待转区
exports.getWareHouseInfo = function(queryCondition, completeFun){
    var entity = entityCollection.getEntity("WareHouse");
    entity.findOne(queryCondition, null, function(err, wareHouseInfo) {
        if (err) {
            completeFun(err);
        } else {
            completeFun(null, wareHouseInfo);
        }
    });
};
